//原文链接
//https://blog.csdn.net/ITSOK_123/article/details/124526013
///递归实现（O(N),O(N)）
void inTraversal(TreeNode* root,vector<int>& vec){
        if(root == nullptr) return;
        inTraversal(root->left,vec);
        vec.push_back(root->val);
        inTraversal(root->right,vec);
    }
    vector<int> inorderTraversal(TreeNode* root) {
        vector<int> ivec;
        inTraversal(root,ivec);
        return ivec;
    }
//迭代实现：（O(N),O(N)）
vector<int> inorderTraversal(TreeNode* root) {
        vector<int> ivec;
        stack<TreeNode*> st;
        TreeNode *node = root;
        while(node ||!st.empty()){
            // 沿着左分支一直下沉
            while(node != nullptr){
                st.push(node);
                node = node->left;
            }
            // 先打印然后再处理右子树
            TreeNode *cur = st.top();
            st.pop();
            ivec.push_back(cur->val);
            node = cur->right;
            
        }
        return ivec;
    }
